package com.show.service.impl;

import com.show.bo.BaseBo;
import com.show.mapper.BaseMapper;
import com.show.pojo.Base;
import com.show.pojo.R;
import com.show.service.BaseService;
import com.show.utils.SqlSessionFactoryUtils;
import com.show.vo.CityCompanyDataVo;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author 绛河
 */

public class BaseServiceImpl implements BaseService {
    SqlSessionFactory factory = SqlSessionFactoryUtils.getSqlSessionFactory();
    @Override
    public List<Base> searchAll() {
        SqlSession sqlSession = factory.openSession();
        BaseMapper mapper = sqlSession.getMapper(BaseMapper.class);
        List<Base> bases = mapper.searchAll();
        return bases;
    }

    @Override
    public Integer searchCount() {
        SqlSession sqlSession = factory.openSession();
        BaseMapper mapper = sqlSession.getMapper(BaseMapper.class);
        Integer integer = mapper.searchCount();
        return integer;
    }

    @Override
    public List<R> searchByGroup() {
        SqlSession sqlSession = factory.openSession();
        BaseMapper mapper = sqlSession.getMapper(BaseMapper.class);
        List<R> bases = mapper.searchByGroup();
        return bases;
    }

    @Override
    public List<Map<String, Object>> searchByNature() {
        SqlSession sqlSession = factory.openSession();
        BaseMapper mapper = sqlSession.getMapper(BaseMapper.class);
        List<Map<String, Object>> maps = mapper.searchByNature();
        return maps;
    }

    @Override
    public List<Map<String, Object>> searchByIndustry() {
        SqlSession sqlSession = factory.openSession();
        BaseMapper mapper = sqlSession.getMapper(BaseMapper.class);
        List<Map<String, Object>> maps = mapper.searchByIndustry();
        return maps;
    }

    @Override
    public List<Map<String, Object>> searchTop() {
        SqlSession sqlSession = factory.openSession();
        BaseMapper mapper = sqlSession.getMapper(BaseMapper.class);
        List<Map<String, Object>> maps = mapper.searchTop();
        return maps;
    }

    /**
     * 省份公司 实习生数据
     */
    @Override
    public List<CityCompanyDataVo> findCityCompany() {
        SqlSession sqlSession = factory.openSession();
        BaseMapper mapper = sqlSession.getMapper(BaseMapper.class);

        //查出城市
        List<BaseBo> provinceCompany = mapper.findProvinceCompany();
        List<CityCompanyDataVo> vo = new ArrayList<>();
        for (BaseBo x : provinceCompany) {
            CityCompanyDataVo cityCompanyDataVo = new CityCompanyDataVo();
            cityCompanyDataVo.setName(x.getName());
            cityCompanyDataVo.setValue(x.getValue());
            //根据省份数据查询 公司和对应的实习生数量
            cityCompanyDataVo.setObjList(mapper.findCompanyByProvince(x.getName()));
            vo.add(cityCompanyDataVo);
        }
        return vo;
    }


}
